﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ExercisesResolution.Models;

namespace ExercisesResolution.Controllers
{
    [HandleError]
    public class HomeController : Controller
    {
        //Exercise 1 solution
        //[ActionName("Content")]
        //public ActionResult ContentExec(string id)
        //{

        //    return View();
        //}

        //Exercise 2 solution
        //[ActionName("Content")]
        //public ActionResult ContentExec(string id)
        //{
        //    Image image = new Image
        //      {
        //          CreationDate = DateTime.Now,
        //          Description = "Header Image for my blog",
        //          ImageUrl = "http://codeclimber.net.nz/Skins/CodeClimber/images/header-logo.jpg",
        //          Title = "CodeClimber Header"
        //      };
        //    return View(image);
        //}

        //Exercise 4 solution
        [ActionName("Content")]
        public ActionResult ContentExec(string id)
        {
            Image image = new Image { Title = "No image selected" };
            if (TempData["Image"] != null)
                image = (Image)TempData["Image"];
            return View(image);
        }

        //Exercise 3 solution
        //public ActionResult Edit()
        //{
        //    return View();
        //}


        //Exercise 4 solution
        [AcceptVerbs("GET")]
        public ActionResult Edit()
        {
            return View();
        }

        //Exercise 4 solution
        [AcceptVerbs("POST")]
        public ActionResult Edit([Bind(Exclude = "CreationDate")] Image image)
        {
            TempData["Message"] = "Image saved!";
            image.CreationDate = DateTime.Now;
            TempData["Image"] = image;
            return RedirectToAction("Content");
        }

        public ActionResult Index()
        {
            return RedirectToAction("Edit");
        }
    }
}
